package com.example.myapplication.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.viewbinding.ViewBinding
import com.chad.library.adapter.base.BaseQuickAdapter

/**
 * @Author:      lsr
 * @CreateDate:  2022/4/27 10:46
 * @Description: 类功能描述说明
 */
abstract class BaseAdapter<T, VB : ViewBinding> : BaseQuickAdapter<T, BaseViewHolder<VB>> {
    private val inflate: (LayoutInflater, ViewGroup, Boolean) -> VB

    constructor(
        inflate: (LayoutInflater, ViewGroup, Boolean) -> VB,
        data: MutableList<T>? = null
    ) : super(0, data) {
        this.inflate = inflate
    }

    constructor(
        inflate: (LayoutInflater, ViewGroup, Boolean) -> VB,
    ) : super(0, null) {
        this.inflate = inflate
    }

    override fun onCreateDefViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder<VB> {
        val viewBinding = inflate(LayoutInflater.from(parent.context), parent, false)
        return BaseViewHolder(viewBinding)
    }
}